import { fileURLToPath, URL } from 'node:url'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
// [vite方式构建项目，monaco-editor组件，右键列表汉化前言 在线编辑代码可以说是非常重要的一个功能，目前在本 - 掘金](https://juejin.cn/post/7351662722906669096)
import MonacoEditorNlsPlugin, {
  esbuildPluginMonacoEditorNls,
  Languages,
} from 'zjt_home_vite-plugin-monaco-editor-nls'
import zh_CN from './src/i18n/vscode/main.i18n.json'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    monacoEditorPlugin({
      languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html'],
    }),
    MonacoEditorNlsPlugin({ locale: Languages.zh_hans, localeData: zh_CN.contents }),
  ],
  optimizeDeps: {
    esbuildOptions: {
      plugins: [
        esbuildPluginMonacoEditorNls({
          locale: Languages.zh_hans,
          localeData: zh_CN.contents,
        }),
      ],
    },
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
